package com.nageoffer.onecoupon.merchant.admin.offer3_24;

public class TwoRunnable {
    private static final Object lock = new Object();
    private static int count = 0;
    private static final int MAX_NUM = 200;
    public static void main(String[] args) {
        Runnable printNum = () -> {
            while(count <= MAX_NUM){
                synchronized (lock){
                    if(count % 2 != 0){
                        System.out.print(count++ + " ");
                        lock.notify();
                    }else {
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };

        Runnable printChar = () -> {
            while(count <= MAX_NUM){
                synchronized (lock){
                    if(count % 2 == 0){
                        System.out.print(count++ + " ");
                        lock.notify();
                    }else {
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        };
        new Thread(printNum).start();
        new Thread(printChar).start();
    }
}
